<?php
namespace app\home\model;

use think\Model;

class Classes extends Model {
    public function index()
    {
        # code...
    }
    public function user()
    {
        # code...
        return $this->belongsTo('user','userid','id')->field('username,avatar,id,title,sex,staus');
    }
    public function post($data)
    {
        $result = $this->save($data);
        if ($result) {
            return 1;
        }else {
            return '投稿失败！';
        }
    }
    public function getTimeAttr($value)
    {
        # code...
        return date('Y-m-d',strtotime($value));
    }
    public function comment()
    {
        # code...
        return $this->hasMany('comment','pid','id');
        //classes是主模型comment关联的模型  
    }

}